package com.personal.gateway.flinkAllCommand.configurationOption.parameterCheck;

import com.personal.gateway.flinkAllCommand.configurationOption.ConfigurationOption;
import com.personal.gateway.flinkAllCommand.configurationOption.configurationType.ConfigurationTypeEnum;
import com.personal.gateway.flinkAllCommand.configurationOption.configurationType.ConfigurationTypeEnumInterface;

/**
 * @author BigHead
 * @date 2022/1/11 10:57
 * @description ParameterCheckString
 */
public class ParameterCheckEnum extends AbstractParameterCheck<Enum<? extends ConfigurationTypeEnumInterface>, ConfigurationTypeEnum> {

    @Override
    public Enum<? extends ConfigurationTypeEnumInterface> abstractCheckValue(ConfigurationOption<Enum<? extends ConfigurationTypeEnumInterface>, ConfigurationTypeEnum> configurationOption, String value) {
        for (Enum<? extends ConfigurationTypeEnumInterface> enumClass: configurationOption.getConfigurationType().getConfigurationType().getEnumConstants()){
            if (null == configurationOption.getAntecedentConfigurationOption()) {
                if (((ConfigurationTypeEnumInterface) enumClass).checkExist(value)) {
                    return enumClass;
                }
            } else {
                if (((ConfigurationTypeEnumInterface) enumClass).checkExist(configurationOption.getAntecedentConfigurationOption(), value)) {
                    return enumClass;
                }
            }
        }
        return null;
    }
}
